package com.dnake.panel;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.KeyEvent;

import com.dnake.WeKerApplication;
import com.dnake.utils.AppUtils;
import com.dnake.utils.SoundPlayUtils;
import com.dnake.utils.SpeechUtils;
import com.wx.android.common.util.SharedPreferencesUtils;

import butterknife.ButterKnife;
import me.yokeyword.fragmentation.SupportActivity;

/**
 * @author haoyuliu
 * @since 2017/7/11
 */

public abstract class BaseActivity extends BaseLabel {
    protected Context mContext;
    protected StringBuffer stringBuffer = new StringBuffer();
    protected abstract int getLayoutResId();
    protected abstract void init(Bundle savedInstanceState);
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        SharedPreferencesUtils.init(this);
        AppUtils.setWindows(this);
        setContentView(getLayoutResId());
        ButterKnife.bind(this);
        WeKerApplication.getContext().addActivity(this);
        init(savedInstanceState);
    }

    @Override
    public void onKey(String key) {
        super.onKey(key);
        if (key.charAt(0)=='0'){
            stringBuffer.append("0");
        }else if (key.charAt(0)=='1'){
            stringBuffer.append("1");
        }else if (key.charAt(0)=='2'){
            stringBuffer.append("2");
        }else if (key.charAt(0)=='3'){
            stringBuffer.append("3");
        }else if (key.charAt(0)=='4'){
            stringBuffer.append("4");
        }else if (key.charAt(0)=='5'){
            stringBuffer.append("5");
        }else if (key.charAt(0)=='6'){
            stringBuffer.append("6");
        }else if (key.charAt(0)=='7'){
            stringBuffer.append("7");
        }else if (key.charAt(0)=='8'){
            stringBuffer.append("8");
        }else if (key.charAt(0)=='9'){
            stringBuffer.append("9");
        }
        keyData(stringBuffer.toString());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        WeKerApplication.getContext().removeActivity(this);
    }
    /**
     * 父类传值给子类
     * @param data
     */
    protected void keyData(String data){}
}
